package zozopo.business.ad;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.comm.Validate;
import zozopo.operations.business.ad.GoodsOS;
import zozopo.operations.business.ad.GoodsTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ModifyGoodsAction extends ActionSupport implements Action,SessionAware{
	private Map<Object, Object> session;
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	private int id_goods;
	//private int views_goods;
	private String useremail_goods;
	private String url_goods;
	private String store_goods;
	private String image_goods;
	private String htmlcode_goods;
	private String content_goods;
	private String name_goods;
	private String kind_goods;
	private String lable_goods;
	private String from_goods;
	private String type_goods;
	//private String date_goods;
	//private String brand_goods;
	private String cnbrand_goods;
	private String enbrand_goods;
	
	public String execute(){
		GoodsOS goodsOS = new GoodsOS();
		GoodsTB goods = new GoodsTB();
		
		
		goods.setId_goods(id_goods);
		goods.setName_goods(name_goods);
		goods.setUrl_goods(url_goods);
		goods.setStore_goods(store_goods);
		goods.setLable_goods(lable_goods);
		goods.setCnbrand_goods(cnbrand_goods);
		goods.setEnbrand_goods(enbrand_goods);
		goods.setType_goods(type_goods);
		goods.setHtmlcode_goods(htmlcode_goods);
		goods.setUseremail_goods(useremail_goods);

		
		
		
		
		
		if(goodsOS.upadteGoods(goods)){
			goodsOS.releaseConnection();
			return SUCCESS;
		}else{
			goodsOS.releaseConnection();
			return ERROR;
		}
	
	}
	
	
	public void validate() {
		// TODO Auto-generated method stub
		 
		if(name_goods == null || name_goods.trim().equals("")){
			addFieldError("errormessage", "网店名称不能为空");
			return;
		}
		
		if(Validate.isSpecialCharacters(name_goods)){
			addFieldError("errormessage", "标题长度不能包含特殊字符 ;\"'\\`|$");
			return;
		}
		
		
		UserTB user = (UserTB) session.get("userInfo");
		if(user == null){
			addFieldError("errormessage", "请登陆后再进行操作");
			return;
		}
		
		if(!UserOS.userFlagLeve(user, 33, 1)){
			addFieldError("errormessage", "权限不足请与管理员联系");
			return;
		}
		
		useremail_goods = user.getUser_email();
		
		
	}
	
	public int getId_goods() {
		return id_goods;
	}
	public void setId_goods(int id_goods) {
		this.id_goods = id_goods;
	}
	public String getUseremail_goods() {
		return useremail_goods;
	}
	public void setUseremail_goods(String useremail_goods) {
		this.useremail_goods = useremail_goods;
	}
	public String getUrl_goods() {
		return url_goods;
	}
	public void setUrl_goods(String url_goods) {
		this.url_goods = url_goods;
	}
	public String getStore_goods() {
		return store_goods;
	}
	public void setStore_goods(String store_goods) {
		this.store_goods = store_goods;
	}
	public String getImage_goods() {
		return image_goods;
	}
	public void setImage_goods(String image_goods) {
		this.image_goods = image_goods;
	}
	public String getHtmlcode_goods() {
		return htmlcode_goods;
	}
	public void setHtmlcode_goods(String htmlcode_goods) {
		this.htmlcode_goods = htmlcode_goods;
	}
	public String getContent_goods() {
		return content_goods;
	}
	public void setContent_goods(String content_goods) {
		this.content_goods = content_goods;
	}
	public String getName_goods() {
		return name_goods;
	}
	public void setName_goods(String name_goods) {
		this.name_goods = name_goods;
	}
	public String getKind_goods() {
		return kind_goods;
	}
	public void setKind_goods(String kind_goods) {
		this.kind_goods = kind_goods;
	}
	public String getLable_goods() {
		return lable_goods;
	}
	public void setLable_goods(String lable_goods) {
		this.lable_goods = lable_goods;
	}
	public String getFrom_goods() {
		return from_goods;
	}
	public void setFrom_goods(String from_goods) {
		this.from_goods = from_goods;
	}
	public String getType_goods() {
		return type_goods;
	}
	public void setType_goods(String type_goods) {
		this.type_goods = type_goods;
	}
	public String getCnbrand_goods() {
		return cnbrand_goods;
	}
	public void setCnbrand_goods(String cnbrand_goods) {
		this.cnbrand_goods = cnbrand_goods;
	}
	public String getEnbrand_goods() {
		return enbrand_goods;
	}
	public void setEnbrand_goods(String enbrand_goods) {
		this.enbrand_goods = enbrand_goods;
	}
	
	
}
